import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Demo02 {
    /*
    1.创建文件demo02.txt
    2.将demo01中的内容复制到demo02中
     */
    public void copy(){
        String filePath1 = "c:\\Users\\86195\\IdeaProjects\\IODemo\\demo01.txt";
        String filePath2 = "c:\\Users\\86195\\IdeaProjects\\IODemo\\demo02.txt";
        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;
        int readLen = 0;
        try {
            fileInputStream = new FileInputStream(filePath1);
            fileOutputStream = new FileOutputStream(filePath2);
            byte[] bytes = new byte[8];
            while((readLen = fileInputStream.read(bytes)) != -1){
                fileOutputStream.write(bytes,0,readLen);
            }
            System.out.println("拷贝成功");
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                if(fileInputStream != null){
                    fileInputStream.close();
                }
                if(fileOutputStream != null){
                    fileOutputStream.close();
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
